package br.com.javamagazine.leilaojm.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;
import br.com.javamagazine.leilaojm.domain.Marca;
import br.com.javamagazine.leilaojm.managedbean.ModeloBean;

@FacesConverter("marcaConverter")
public class MarcaConverter implements Converter {
	@Inject
	private ModeloBean modeloBean;

	@Override
	public Object getAsObject(FacesContext contexto, UIComponent componente,
			String marcaStr) {
		Marca marcaObjeto = modeloBean.retornaMarcaPeloNome(marcaStr);
		return (Marca) marcaObjeto;
	}

	@Override
	public String getAsString(FacesContext contexto, UIComponent component,
			Object marcaObjeto) {
		return ((Marca) marcaObjeto).getNome();
	}
}
